import {Injectable} from "@angular/core";
import {Http} from "@angular/http";
import {HttpService} from "./HttpService";
import {ms_loginUser} from  "./model/ms_loginUser"

import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise';

import {ResponseData} from "./model/ResponseData";
import {UserToken} from "./model/UserToken";
import {MD5} from "./units/md5";


@Injectable()
export class LoginService extends HttpService{

    protected url="Login";


    constructor(private http:Http){
        super();
    }

    public Login(user:ms_loginUser):Promise<ResponseData<UserToken>>{

        return this.http.post(this.prefix + this.url,
            {
                userName:user.userName,
                password:user.encrypt()
            })
            .map(response => {
                return response.json() as ResponseData<UserToken>;
            }).toPromise();
    }


}